const KoaRouter = require('@koa/router')
const userController = require('../controller/user.controller')
const { verifyUser, handlePassword, verifyExist } = require('../middleware/user.middleware')
const { verifyAuthorization } = require('../middleware/login.middleware')
const { verifyEmailCode } = require('../middleware/email.middleware')

const userRouter = new KoaRouter({ prefix: '/users' })

// 2.1 用户注册接口
userRouter.post('/register', verifyEmailCode, verifyUser, handlePassword, userController.create)

// 2.2 登陆用户的信息
/**
 * 直接查询用户的信息
 */
userRouter.get('/:id', userController.getUserInfo)

// 2.3 根据不同角色权限查询相关的菜餐
userRouter.get('/menus/:roleId', userController.getMenusList)

// 2.4 查询用户的全部信息
userRouter.get('/', userController.getAllUserInfo)

// 2.5 更新用户的信息
userRouter.put('/:id', verifyAuthorization, userController.updateUserInfo)

// 2.6 删除用户
userRouter.delete('/:id', verifyAuthorization, userController.deleteUser)

// 2.2 为用户提供头像展示
userRouter.get('/avatar/:userId', userController.showAvatarImage)

// 2.8修改密码
userRouter.post('/update/password', verifyEmailCode, verifyExist, handlePassword, userController.updatePassword)

// 2.9验证是否存在
userRouter.post('/update/exist', verifyEmailCode, verifyExist, userController.isExist)
module.exports = userRouter
